using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.DataHelper;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class ShowWitkey : Shop, IRequiresSessionState
{
	private DataRow WitkeyInfo;
	private DataRow UserInfo;
	private DataTable WorkInfo;
	private DataRow WorkStatuInfo;
	private int Id = Fetch.GetID("ww_Id");
	protected HtmlHead Head1;
	protected HtmlInputHidden input_hidden;
	protected HtmlInputHidden input_Uid;
	protected HtmlInputHidden input_login;
	protected Label label_Title;
	protected Label label_Price;
	protected Label label_ID;
	protected Label label_StarTime;
	protected Label label_EndTime;
	protected Label label_Statu;
	protected Label label_xsMode;
	protected HtmlGenericControl divTask;
	protected HtmlGenericControl span_result;
	protected Button task_btn1;
	protected HtmlInputButton task_btn2;
	protected HtmlInputButton task_btn3;
	protected Label label_User;
	protected Label label_UserName;
	protected Label label_RegTime;
	protected Label label_Email;
	protected Label label_Phone;
	protected Label label_Win;
	protected HtmlGenericControl Span_Desc;
	protected LinkButton LinkButton_1;
	protected HtmlGenericControl tab_cont3_1;
	protected LinkButton LinkButton_2;
	protected HtmlGenericControl tab_cont3_2;
	protected LinkButton LinkButton_3;
	protected HtmlGenericControl tab_cont3_3;
	protected Label label_Content;
	protected HtmlGenericControl div_cont3_1;
	protected Repeater Repeater_Work;
	protected HtmlGenericControl div_cont3_2;
	protected Repeater Repeater_Message;
	protected HtmlGenericControl div_cont3_3;
	protected HtmlGenericControl span_Participants;
	protected Repeater repeater_Participants;
	protected TextBox WorkContent;
	protected HtmlGenericControl WorkDiv;
	protected TextBox MesssageContent;
	protected HtmlGenericControl MessageDiv;
	protected Button Button_OK;
	protected HtmlGenericControl div2;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Init(object sender, EventArgs e)
	{
		try
		{
			Template.BindTemplateToPage(this.Page, "SaleProduct");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.Initpage();
		}
		if (!base.user.CheckUserLogin())
		{
			this.task_btn1.Visible = false;
			this.task_btn2.Visible = false;
			this.task_btn3.Visible = false;
			this.label_Email.Visible = false;
			this.label_Phone.Visible = false;
		}
	}
	protected void Initpage()
	{
		if (!base.user.CheckUserLogin())
		{
			this.task_btn1.Visible = false;
		}
		this.WorkDetailedBind();
		this.UserInfoBind();
		this.WorkBind();
		this.WorkDescBind();
		this.UpdateEnd();
		this.div_cont3_1.Visible = true;
		this.div_cont3_2.Visible = false;
		this.div_cont3_3.Visible = false;
		this.MesssageContent.Text = "";
		string a = this.WitkeyInfo["ww_Statu"].ToString();
		string a2 = this.WitkeyInfo["ww_Type"].ToString();
		this.input_Uid.Value = this.WitkeyInfo["ww_Uid"].ToString();
		this.input_login.Value = base.user.UserID.ToString();
		if (a == "未付款" || a == "待审核" || a == "审核失败")
		{
			if (a2 == "1")
			{
				this.divTask.Attributes.Add("class", "task_progress");
			}
			else
			{
				this.divTask.Attributes.Add("class", "task_tender");
			}
			this.span_result.InnerHtml = "等待审核或付款……";
			this.task_btn1.Visible = false;
			this.task_btn2.Visible = false;
			this.task_btn3.Visible = false;
		}
		else
		{
			if (a == "进行中")
			{
				if (a2 == "1")
				{
					this.divTask.Attributes.Add("class", "task_progress");
				}
				else
				{
					this.divTask.Attributes.Add("class", "task_tender2");
				}
				this.task_btn1.Visible = true;
				this.task_btn2.Visible = true;
				this.task_btn3.Visible = true;
			}
			else
			{
				if (a == "公示中" || a == "投票中")
				{
					if (a2 == "1")
					{
						this.divTask.Attributes.Add("class", "task_progress2");
					}
					else
					{
						this.divTask.Attributes.Add("class", "task_tender2");
					}
					this.task_btn1.Visible = true;
					this.task_btn2.Visible = true;
					this.task_btn3.Visible = true;
				}
				else
				{
					if (a == "任务失败")
					{
						if (a2 == "1")
						{
							this.divTask.Attributes.Add("class", "task_progress3");
						}
						else
						{
							this.divTask.Attributes.Add("class", "task_tender3");
						}
						this.span_result.InnerHtml = "指定时间内未完成，任务失败！";
						this.task_btn1.Visible = false;
						this.task_btn2.Visible = false;
						this.task_btn3.Visible = false;
					}
					else
					{
						if (a == "冻结")
						{
							if (a2 == "1")
							{
								this.divTask.Attributes.Add("class", "task_progress3");
							}
							else
							{
								this.divTask.Attributes.Add("class", "task_tender3");
							}
							this.span_result.InnerHtml = "任务进入冻结。";
							this.task_btn1.Visible = false;
							this.task_btn2.Visible = false;
							this.task_btn3.Visible = false;
						}
						else
						{
							if (a == "任务结束")
							{
								if (a2 == "1")
								{
									this.divTask.Attributes.Add("class", "task_progress3");
								}
								else
								{
									this.divTask.Attributes.Add("class", "task_tender3");
								}
								this.span_result.InnerHtml = "任务完满结束！";
								this.task_btn1.Visible = false;
								this.task_btn2.Visible = false;
								this.task_btn3.Visible = false;
							}
						}
					}
				}
			}
		}
		if (this.WitkeyInfo["ww_Uid"].ToString() == base.user.UserID.ToString())
		{
			this.task_btn1.Visible = false;
			this.task_btn2.Visible = false;
			this.task_btn3.Visible = false;
		}
	}
	protected void UpdateEnd()
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		DataTable witkeyAll = shop_Witkey.GetWitkeyAll();
		DateTime now = DateTime.Now;
		foreach (DataRow dataRow in witkeyAll.Rows)
		{
			DateTime t = Convert.ToDateTime(dataRow["ww_EndTime"]);
			if (now >= t)
			{
				string a = dataRow["ww_Statu"].ToString();
				if (a != "8" && a != "9" && a != "7" && a != "5" && a != "6" && a != "5" && a != "1")
				{
					shop_Witkey.UpdateWitkeyStatu(Convert.ToInt32(dataRow["ww_Id"]), 7);
					int userID = Convert.ToInt32(dataRow["ww_Uid"]);
					UserBll userBll = new UserBll(this.conn);
					DataTable userByUserID = userBll.GetUserByUserID(userID);
					userBll.UpdateUserScope(userID, Convert.ToDecimal(userByUserID.Rows[0]["Balance"]) + Convert.ToDecimal(dataRow["ww_xsPrice"]), Convert.ToInt32(userByUserID.Rows[0]["UserEP"]));
				}
			}
		}
	}
	protected void WorkDetailedBind()
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		DataTable witkey = shop_Witkey.GetWitkey(this.Id);
		DataTable witkeyWorkStatu = shop_Witkey.GetWitkeyWorkStatu(this.Id, 8);
		this.WitkeyInfo = witkey.Rows[0];
		this.label_User.Text = this.WitkeyInfo["ww_UserName"].ToString();
		this.label_Title.Text = this.WitkeyInfo["ww_Title"].ToString();
		this.label_Content.Text = this.WitkeyInfo["ww_Content"].ToString();
		this.label_ID.Text = this.WitkeyInfo["ww_Id"].ToString();
		this.label_StarTime.Text = this.WitkeyInfo["ww_StartTime"].ToString();
		this.label_EndTime.Text = this.WitkeyInfo["ww_EndTime"].ToString();
		this.label_Statu.Text = this.WitkeyInfo["ww_Statu"].ToString();
		this.label_Email.Text = this.WitkeyInfo["ww_Email"].ToString();
		this.label_Phone.Text = this.WitkeyInfo["ww_Phone"].ToString();
		this.span_Participants.InnerHtml = this.WitkeyInfo["ww_Participants"].ToString();
		if (this.WitkeyInfo["ww_Type"].ToString() == "1")
		{
			this.label_Win.Text = "<strong>中标稿件</strong>：";
			this.label_Price.Text = this.WitkeyInfo["ww_xsPrice"].ToString();
			this.label_xsMode.Text = "单人中标，一人独享奖金。 ";
			this.Span_Desc.InnerHtml = "<p>稿件如果被客户选中，在完成赏金支付后。</p><p>本站能确保该项目悬赏金的80%付与中标者！</p>";
		}
		else
		{
			this.label_Price.Text = this.WitkeyInfo["ww_zbPrice"].ToString();
			this.Span_Desc.InnerHtml = "<p>招标任务全免费啦！完成任务获100%赏金！</p>";
		}
		if (witkeyWorkStatu.Rows.Count > 0)
		{
			this.WorkStatuInfo = witkeyWorkStatu.Rows[0];
			this.label_Win.Text = string.Concat(new string[]
			{
				"<strong>中标稿件</strong>：<font color='red'>",
				this.WorkStatuInfo["UserName"].ToString(),
				"</font>中标， ",
				this.WorkStatuInfo["work_Id"].ToString(),
				"号稿件，中标时间：[",
				this.WorkStatuInfo["work_Date"].ToString(),
				"]"
			});
		}
	}
	protected void UserInfoBind()
	{
		UserInfoBll userInfoBll = new UserInfoBll(this.conn);
		DataTable userInfoByUserID = userInfoBll.GetUserInfoByUserID(Convert.ToInt32(this.WitkeyInfo["ww_Uid"]));
		this.UserInfo = userInfoByUserID.Rows[0];
		this.label_UserName.Text = this.UserInfo["UserName"].ToString();
		this.label_RegTime.Text = this.UserInfo["RegTime"].ToString();
	}
	protected void MessaageBind()
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.Repeater_Message.DataSource = shop_Witkey.GetWitkeyMessage(this.Id);
		this.Repeater_Message.DataBind();
	}
	protected void WorkBind()
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.WorkInfo = shop_Witkey.GetWitkeyWork(this.Id);
		this.repeater_Participants.DataSource = this.WorkInfo;
		this.repeater_Participants.DataBind();
		this.Repeater_Work.DataSource = this.WorkInfo;
		this.Repeater_Work.DataBind();
	}
	protected void LinkButton_Command(object sender, CommandEventArgs e)
	{
		this.Initpage();
		string commandName = e.CommandName;
		if (commandName != null)
		{
			if (!(commandName == "1"))
			{
				if (!(commandName == "2"))
				{
					if (commandName == "3")
					{
						this.div_cont3_1.Visible = false;
						this.div_cont3_2.Visible = false;
						this.div_cont3_3.Visible = true;
						this.tab_cont3_1.Attributes.Add("class", "");
						this.tab_cont3_2.Attributes.Add("class", "");
						this.tab_cont3_3.Attributes.Add("class", "now");
						this.MessaageBind();
					}
				}
				else
				{
					this.div_cont3_1.Visible = false;
					this.div_cont3_2.Visible = true;
					this.div_cont3_3.Visible = false;
					this.tab_cont3_1.Attributes.Add("class", "");
					this.tab_cont3_2.Attributes.Add("class", "now");
					this.tab_cont3_3.Attributes.Add("class", "");
					this.WorkBind();
				}
			}
			else
			{
				this.div_cont3_1.Visible = true;
				this.div_cont3_2.Visible = false;
				this.div_cont3_3.Visible = false;
				this.tab_cont3_1.Attributes.Add("class", "now");
				this.tab_cont3_2.Attributes.Add("class", "");
				this.tab_cont3_3.Attributes.Add("class", "");
			}
		}
	}
	protected void task_btn1_Click(object sender, EventArgs e)
	{
		try
		{
			this.Initpage();
			Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
			int userID = base.user.UserID;
			string userName = base.user.UserName;
			int num = Convert.ToInt32(this.WitkeyInfo["ww_Uid"]);
			int count = shop_Witkey.GetWitkeyWorkUser(this.Id, userID).Rows.Count;
			DataTable witkeyUserInfo = shop_Witkey.GetWitkeyUserInfo(userID);
			if (userID != num && count == 0)
			{
				if (witkeyUserInfo.Rows.Count < 1)
				{
					shop_Witkey.AddWitkeyUserInfo(userID, 0);
				}
				shop_Witkey.AddWitkeyWork(this.Id, userID, userName, "", "", "", DateTime.Now, 0);
				shop_Witkey.UpdateWitkeyCount(this.Id, Convert.ToInt32(this.WitkeyInfo["ww_Participants"]) + 1, Convert.ToInt32(this.WitkeyInfo["ww_Complete"]));
				base.Server.Transfer("ResultWitkey.aspx?Type=Success&&ww_Id=" + this.Id.ToString());
			}
			else
			{
				if (userID == num)
				{
					base.Server.Transfer("ResultWitkey.aspx?Type=As&&ww_Id=" + this.Id.ToString());
				}
				else
				{
					if (userID != num && count == 1)
					{
						base.Server.Transfer("ResultWitkey.aspx?Type=Add&&ww_Id=" + this.Id.ToString());
					}
				}
			}
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[0]);
		}
	}
	protected void Button_OK_Click(object sender, EventArgs e)
	{
		string value = this.input_hidden.Value;
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		DataTable witkeyWorkUser = shop_Witkey.GetWitkeyWorkUser(this.Id, base.user.UserID);
		int count = witkeyWorkUser.Rows.Count;
		this.WorkDetailedBind();
		if (this.input_Uid.Value != base.user.UserID.ToString())
		{
			if (value == "1")
			{
				if (count <= 0)
				{
					shop_Witkey.AddWitkeyWork(this.Id, base.user.UserID, base.user.UserName, "", this.WorkContent.Text, "", DateTime.Now, 0);
				}
				else
				{
					if (count > 0)
					{
						string text = witkeyWorkUser.Rows[0]["work_Desc"].ToString().Trim();
						shop_Witkey.UpdateWitkeyWork(Convert.ToInt32(witkeyWorkUser.Rows[0]["work_Id"]), this.Id, "", this.WorkContent.Text, "", Convert.ToInt32(witkeyWorkUser.Rows[0]["work_statu"]));
						if (text == "" || text == null)
						{
							shop_Witkey.UpdateWitkeyCount(this.Id, Convert.ToInt32(this.WitkeyInfo["ww_Participants"]), Convert.ToInt32(this.WitkeyInfo["ww_Complete"]) + 1);
						}
					}
				}
			}
			else
			{
				if (value == "2")
				{
					shop_Witkey.AddWitkeyMessage(this.Id, base.user.UserID, DateTime.Now, this.MesssageContent.Text);
				}
			}
			this.Initpage();
		}
		else
		{
			base.Server.Transfer("ResultWitkey.aspx?Type=As&&ww_Id=" + this.Id.ToString());
		}
	}
	protected void WorkDescBind()
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		DataTable witkeyWorkUser = shop_Witkey.GetWitkeyWorkUser(this.Id, base.user.UserID);
		if (witkeyWorkUser.Rows.Count > 0)
		{
			this.WorkContent.Text = witkeyWorkUser.Rows[0]["work_Desc"].ToString();
		}
		else
		{
			this.WorkContent.Text = "";
		}
	}
	protected void Repeater_Work_ItemDataBound(object sender, RepeaterItemEventArgs e)
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey();
		DataTable witkeyWorkStatu = shop_Witkey.GetWitkeyWorkStatu(this.Id, 8);
		if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
		{
			HyperLink hyperLink = (HyperLink)e.Item.FindControl("HyperLink_In");
			HyperLink hyperLink2 = (HyperLink)e.Item.FindControl("HyperLink_Win");
			Image image = (Image)e.Item.FindControl("Image_Statu");
			DataRowView dataRowView = e.Item.DataItem as DataRowView;
			string text = dataRowView["work_statu"].ToString();
			string text2 = text;
			if (text2 != null)
			{
				if (text2 == "5")
				{
					image.ImageUrl = "~/Witkey/img/ruwei.gif";
					goto IL_112;
				}
				if (text2 == "8")
				{
					image.ImageUrl = "~/Witkey/img/zhongbiao.gif";
					goto IL_112;
				}
			}
			image.Visible = false;
			IL_112:
			if (this.WitkeyInfo["ww_Uid"].ToString() == base.user.UserID.ToString())
			{
				hyperLink.Visible = true;
				hyperLink2.Visible = true;
				if (text == "5")
				{
					hyperLink.Visible = false;
				}
				if (witkeyWorkStatu.Rows.Count > 0)
				{
					hyperLink.Visible = false;
					hyperLink2.Visible = false;
				}
			}
			else
			{
				hyperLink.Visible = false;
				hyperLink2.Visible = false;
			}
		}
	}
}
